package com.aptoto.thrift.offcial.separation;

import java.util.BitSet;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TTupleProtocol;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.TupleScheme;

public class MTupleSchemeFactory implements SchemeFactory {
	public MTupleScheme getScheme() {
		return new MTupleScheme();
	}
	
	public static class MTupleScheme extends TupleScheme<M> {

		@Override
		public void write(TProtocol prot, M struct) throws TException {
			TTupleProtocol oprot = (TTupleProtocol) prot;
			BitSet optionals = new BitSet();
			if (struct.isSetAa()) {
				optionals.set(0);
			}
			if (struct.isSetBb()) {
				optionals.set(1);
			}
			if (struct.isSetCc()) {
				optionals.set(2);
			}
			if (struct.isSetDd()) {
				optionals.set(3);
			}
			if (struct.isSetEe()) {
				optionals.set(4);
			}
			if (struct.isSetFf()) {
				optionals.set(5);
			}
			if (struct.isSetGg()) {
				optionals.set(6);
			}
			if (struct.isSetHh()) {
				optionals.set(7);
			}
			if (struct.isSetIi()) {
				optionals.set(8);
			}
			oprot.writeBitSet(optionals, 9);
			if (struct.isSetAa()) {
				oprot.writeBool(struct.aa);
			}
			if (struct.isSetBb()) {
				oprot.writeByte(struct.bb);
			}
			if (struct.isSetCc()) {
				oprot.writeI16(struct.cc);
			}
			if (struct.isSetDd()) {
				oprot.writeI32(struct.dd);
			}
			if (struct.isSetEe()) {
				oprot.writeI64(struct.ee);
			}
			if (struct.isSetFf()) {
				oprot.writeDouble(struct.ff);
			}
			if (struct.isSetGg()) {
				oprot.writeString(struct.gg);
			}
			if (struct.isSetHh()) {
				oprot.writeString(struct.hh);
			}
			if (struct.isSetIi()) {
				oprot.writeI32(struct.ii);
			}
		}

		@Override
		public void read(TProtocol prot, M struct) throws TException {
			TTupleProtocol iprot = (TTupleProtocol) prot;
			BitSet incoming = iprot.readBitSet(9);
			if (incoming.get(0)) {
				struct.aa = iprot.readBool();
				struct.setAaIsSet(true);
			}
			if (incoming.get(1)) {
				struct.bb = iprot.readByte();
				struct.setBbIsSet(true);
			}
			if (incoming.get(2)) {
				struct.cc = iprot.readI16();
				struct.setCcIsSet(true);
			}
			if (incoming.get(3)) {
				struct.dd = iprot.readI32();
				struct.setDdIsSet(true);
			}
			if (incoming.get(4)) {
				struct.ee = iprot.readI64();
				struct.setEeIsSet(true);
			}
			if (incoming.get(5)) {
				struct.ff = iprot.readDouble();
				struct.setFfIsSet(true);
			}
			if (incoming.get(6)) {
				struct.gg = iprot.readString();
				struct.setGgIsSet(true);
			}
			if (incoming.get(7)) {
				struct.hh = iprot.readString();
				struct.setHhIsSet(true);
			}
			if (incoming.get(8)) {
				struct.ii = iprot.readI32();
				struct.setIiIsSet(true);
			}
		}
	}
}
